To accomplish multitasking, processes in computer systems running on contemporary operating systems such as Microsoft Corporation's Windows.RTM. NT.TM. or Windows.RTM. 95 contain one or more threads of execution. The processor switches control among the threads, which are coded like functions. In one threading architecture known as the apartment model, processes are divided into apartments, with one thread possessing a set of objects per apartment. To invoke an object's methods, an object is called through an interface proxy. The interface proxy switches to the thread of the object's apartment.
An interprocess communication mechanism allows a thread of one process to communicate with and pass data to a thread of another process. Basically, the mechanism allows a client process to send a request to a remote server process. However, if a client thread retains control and blocks pending a reply from the server, the client application will freeze until the reply is received. Since freezing an application is not desirable, a blocking function is provided so that the client can do other work such as reading messages from its message queue and dispatching them. A worker thread in OLE makes the call to the server via a synchronous, blocking local remote procedure call (LRPC), and blocks waiting for the reply. In this manner, while the call is in progress, the client application thread is free to perform other non-conflicting work, such as processing and dispatching messages.
On the server side, an RPC dispatch thread dispatches the call to OLE, which then blocks the dispatch thread, picks up the call and posts a message to the object's thread. The message asks the server application to pick up the request. Some time later, the server application executes the remote call, and returns reply data to the dispatch thread. The dispatch thread then unblocks and returns the call to the server RPC runtime to send the reply back to the client.
While the use of worker and dispatch threads thus provides desirable features, i.e., recursive calls between client and server object threads are allowed and applications are not blocked awaiting replies and receipt of requests and replies, such a mechanism is not very efficient. In particular, each call requires at least two thread-switching operations (i.e., two thread switches, one from the client thread to the worker thread and one back to the client thread) on the client and two thread switches on the server. Each thread switch involves saving one thread's context and loading another thread's context. Moreover, one worker thread is dedicated for each outstanding call made by the client, and a dispatch thread is dedicated for each dispatched call on the server. Multiple calls thus require multiple dedicated threads. Such an approach is thus expensive in terms of the number of threads used, and it is relatively slow.